package com.example.demonstrate.wang.entity;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;

import java.util.Map;

/**
 * @Author along
 * @Date 2024/6/11 17:43
 * @Description 档案
 */

@Data
@Document(indexName = "profile")
public class Profile {

    @Id
    private String profileId;

    private long profileIdOri;

    @Field
    private Boolean profileType;

    private String personId;

    @Field
    private long createdTime;

    private long updateTime;

    @Field
    private boolean isDelete;

    @Field
    private int faceCount;

    private String cardId;

    private int age;

    private String gender;

    private String minority;

    private String coverPageImageUri;

    private String photoId;

    private String coverPageImgFaceId;

    private String photoAlbums;


    // 构造函数，用于从Map中初始化Profile
    public Profile(Map<String, Object> hitSource) {
        ObjectMapper mapper = new ObjectMapper();
        try {
            Profile profile = mapper.readValue(mapper.writeValueAsString(hitSource), Profile.class);
            this.profileId = profile.getProfileId();
            this.profileIdOri = profile.getProfileIdOri();
            this.profileType = profile.getProfileType();
            this.personId = profile.getPersonId();
            this.createdTime = profile.getCreatedTime();
            this.updateTime = profile.getUpdateTime();
            this.isDelete = profile.isDelete();
            this.faceCount = profile.getFaceCount();
            this.cardId = profile.getCardId();
            this.age = profile.getAge();
            this.gender = profile.getGender();
            this.minority = profile.getMinority();
            this.coverPageImageUri = profile.getCoverPageImageUri();
            this.photoId = profile.getPhotoId();
            this.coverPageImgFaceId = profile.getCoverPageImgFaceId();
            this.photoAlbums = profile.getPhotoAlbums();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
